package me.minecraft.plugin.pokemondenyconvert.listener;

import com.cobblemon.mod.common.pokemon.Pokemon;
import lg.minecraft.plugin.pokemonmenu.event.ItemToPokemonEvent;
import lg.minecraft.plugin.pokemonmenu.event.PokemonToItemEvent;
import me.minecraft.plugin.pokemondenyconvert.PokemonDenyConvert;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class PokemonEvent implements Listener {

    @EventHandler
    public void onPokemonToItem(PokemonToItemEvent event) {
        if (event.isCancelled()) return;
        Player player = event.getPlayer();
        Pokemon pokemon = event.getPokemon();
        if (player.hasPermission("PokemonDenyConvert.bypass.pokemon_to_item")) return;
        if (!PokemonDenyConvert.getMainConfig().isPokemonToItem()) return;
        if (!PokemonDenyConvert.getMainConfig().matches(pokemon)) return;
        event.setCancelled(true);
        player.sendMessage(PokemonDenyConvert.getMainConfig().getMessage());
    }

    @EventHandler
    public void onItemToPokemon(ItemToPokemonEvent event) {
        if (event.isCancelled()) return;
        Player player = event.getPlayer();
        Pokemon pokemon = event.getPokemon();
        if (player.hasPermission("PokemonDenyConvert.bypass.item_to_pokemon")) return;
        if (!PokemonDenyConvert.getMainConfig().isItemToPokemon()) return;
        if (!PokemonDenyConvert.getMainConfig().matches(pokemon)) return;
        event.setCancelled(true);
        player.sendMessage(PokemonDenyConvert.getMainConfig().getMessage());
    }

}
